package kubayaxi.video.client.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import kubayaxi.video.client.request.login.LoginDTO;
import kubayaxi.video.client.request.login.LoginSendCodeDTO;
import kubayaxi.video.client.response.login.LoginVO;
import kubayaxi.video.client.service.ILoginService;
import kubayaxi.video.service.base.common.request.BaseRequest;
import kubayaxi.video.service.base.common.response.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/client/login")
@Api(tags = "客户端【登录】")
public class LoginController {
    @Autowired
    private ILoginService loginService;

    @PostMapping("/sendCode")
    @ApiOperation("发送验证码")
    public ResponseResult sendCode(@RequestBody BaseRequest<LoginSendCodeDTO> dto){
        loginService.sendCode(dto);
        return ResponseResult.success();
    }

    @PostMapping("login")
    @ApiOperation("用户登录")
    public ResponseResult<LoginVO> login(@RequestBody BaseRequest<LoginDTO> dto, HttpServletRequest request) {
        LoginVO ans = loginService.login(dto, request);
        return ResponseResult.success(ans);
    }
}
